package org.qfedu.edu.seckill.autoconfig;

import org.qfedu.edu.seckill.service.IJwtService;
import org.qfedu.edu.seckill.service.ITokenService;
import org.qfedu.edu.seckill.service.impl.JwtService;
import org.qfedu.edu.seckill.service.impl.TokenService;
import org.qfedu.edu.seckill.properties.TokenInfoProperties;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

@SpringBootConfiguration
@EnableConfigurationProperties(value = TokenInfoProperties.class)  //引入这个属性的配置文件
public class JwtTokenServiceAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public IJwtService jwtService(){
        IJwtService jwtService=new JwtService();
        return jwtService;
    }


    @Bean
    @ConditionalOnMissingBean
    public ITokenService tokenService(TokenInfoProperties tokenInfoProperties){
        TokenService tokenService=new TokenService();
        tokenService.setExpire(tokenInfoProperties.getExpire());
        tokenService.setSign(tokenInfoProperties.getSign());
        return tokenService;
    }


}
